package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.dto.api.ApiProductSearchDTO;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.api.product.ProductItemVO;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.product.service.ProductService;
import com.atguigu.spzx.product.service.ProductSkuService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Resource
    ProductService productService;
    @Resource
    ProductSkuService productSkuService;
    @GetMapping("sku/{skuId}")
    public Result getSkuBySkuId(@PathVariable("skuId")Long skuId){
        ProductSku productSku = productSkuService.getById(skuId);
        return Result.ok().data(productSku);
    }
    @GetMapping("/item/{skuId}")
    public Result getItemBySkuId(@PathVariable("skuId")Long skuId){
        ProductItemVO productItemVO = productService.getItemBySkuId(skuId);
        return Result.ok().data(productItemVO);
    }

    @GetMapping("/{pageNum}/{pageSize}")
    public Result list(@PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize,
                       ApiProductSearchDTO productSearchDTO){
        //前端需要的是 PageInterceptor中的pageInfo对象解析展示
        //后端使用mp的分页查询只能使用mp的Page对象封装
        PageInfo<ProductSku> page = productService.list(pageNum, pageSize , productSearchDTO);
        return Result.ok().data(page);
    }
}
